package main

import (
	"fmt"
	"log"
	"net"
	"time"
)

func chkError(err error) {
	if err != nil {
		log.Fatal(err)
	}
}

func handelClient(conn net.Conn) {
	defer conn.Close()

	conn.Write([]byte("hello" + time.Now().String()))
}

func main() {
	port := "127.0.0.1:1234"
	tcpaddr, err := net.ResolveTCPAddr("tcp4", port)
	chkError(err)
	fmt.Println("服务启动,监听" + port)

	tcplisten, err2 := net.ListenTCP("tcp", tcpaddr)
	chkError(err2)

	for {
		conn, err3 := tcplisten.Accept()

		if err3 != nil {
			continue
		}

		go handelClient(conn)
	}
}
